package com.hainatong.jcmvvmbase.dbtoolroom;


import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;


/**
 * 使用Room 第1步 建表
 * @author jingbin
 * @date 2017/12/30
 * @description 注意：1、建值如果为 String id; 使用getWid(),则会报错！！！
 * 2、有一个key就要有对应的get和set
 * 3、List<>不能简单使用，需要处理
 */

/*
 *  类加上@Entity标签 将该类与Room中表关联起来。
 *  tableName属性设置该表名字，如果不设置，则表名与类名相同。
 */
@Entity(tableName = "User")
public class User
{

    /**
     * PrimaryKey指定表的主键。
     * 通过主键来标识删除的
     * 主键递增：PrimaryKey(autoGenerate = true)
     * ColumnInfo设置表中的名字并指定字段的类型。
     * @ColumnInfo(name = "id", typeAffinity = ColumnInfo.INTEGER)
     * @ColumnInfo(name = "name", typeAffinity = ColumnInfo.TEXT)
     *
     * @Ignore标签用来告诉系统忽略该字段或者方法。
     */

    @PrimaryKey
    @NonNull
    @ColumnInfo(name = "id")
    private int id;

    @ColumnInfo(name = "level")
    private String level;

    @ColumnInfo(name = "age")
    private int age;

    @ColumnInfo(name = "username")
    private String username;

    @ColumnInfo(name = "rank")
    private int rank;

//    @ColumnInfo(name = "collectIds")
//    private List<Integer> collectIds;

    //这里定义User 和 Book的关系
//    @Relation(parentColumn = "id", entityColumn = "id", entity = Integer.class)
//    private ArrayList<Integer> collectIds;


    /**
     * Room会使用这个构造器来存储数据，也就是当你从表中得到User对象时候，Room会使用这个构造器
     *
     * */
    public User(@NonNull int id, String level, int age, String username, int rank)
    {
        this.id = id;
        this.level = level;
        this.age = age;
        this.username = username;
        this.rank = rank;
    }

    @Ignore
    public User(String level, int age, String username, int rank)
    {
        this.level = level;
        this.age = age;
        this.username = username;
        this.rank = rank;
    }

    @NonNull
    public int getId()
    {
        return id;
    }

    public void setId(@NonNull int id)
    {
        this.id = id;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }


    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", level='" + level + '\'' +
                ", age=" + age +
                ", username='" + username + '\'' +
                ", rank=" + rank +
                '}';
    }
}
